<template>
  <view>
    <mian-index ref="childer" @send="getSonValue"></mian-index>
    <button
      v-if="sonvalue.isVerified && sonvalue.isVerified == 1"
      @click="editor"
      class="arc_button btn_appointment"
    >
      实名认证
    </button>
    <button class="btn_appointment arc_button" type="default" @click="last">
      下一步
    </button>
  </view>
</template>

<script>
import { childer } from '@/pagesSub/components/ofPatient.vue'
import { patientList, doctorList } from '@/api/prescribing.js'
import { undoneConsult } from '@/api/user.js'
import store from '@/store'
export default {
  components: {
    'mian-index': childer,
  },
  data() {
    return {
      info: [],
      choosePeopleInfo: [],
      sonvalue: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      serviceInfo: [],
      typeStatus: {
        1: '图文咨询',
        2: '用药咨询',
        3: '免费咨询',
      },
      type: 0,
    }
  },
  onLoad: function (option) {
    if (option.serviceInfo) {
      let medical = JSON.parse(decodeURIComponent(option.serviceInfo))
      this.serviceInfo = medical //服务人员信息
    }
  },
  onShow() {
    this.$refs.childer.patientListInfo()
    this.$refs.childer.peopleNumber()
    this.sonvalue = {}
  },
  methods: {
    getSonValue: function (res) {
      this.sonvalue = res //选择的就诊人信息
      console.log(
        '*******sonvalue',
        this.sonvalue,
        // JSON.stringify(this.sonvalue),
        this.serviceInfo,
      )
    },
    patientListInfo() {
      let _this = this
      uni.showLoading({
        title: '加载中',
      })
      patientList(_this.queryParams)
        .then((res) => {
          _this.info = res.rows
          uni.hideLoading()
        })
        .catch((res) => {
          uni.hideLoading()
        })
    },
    doctorLists() {
      let _this = this
      uni.showLoading({
        title: '加载中',
      })
      doctorList(_this.queryParams)
        .then((res) => {
          // _this.info=res.rows;
          uni.hideLoading()
        })
        .catch((res) => {
          uni.hideLoading()
        })
    },

    last() {
      //   this.sonvalue.type = this.consultType
      if (this.sonvalue && this.sonvalue.isVerified == 0) {
        // 点下一步是跳转到聊天页面

        // let items = encodeURIComponent(JSON.stringify(this.sonvalue))
        //   this.serviceInfo
        // 选择的就诊人信息合并到传进来的信息里
        this.serviceInfo = Object.assign( this.sonvalue, this.serviceInfo)
        let serviceInfo = encodeURIComponent(JSON.stringify(this.serviceInfo))

        console.log(this.serviceInfo, '和服务人员和就诊人信息--')
        uni.navigateTo({
          //   服务人员跳转到聊天页面
          url: `/pagesSub/service/serviceToChat?item=${serviceInfo}`,
        })

        // let items = encodeURIComponent(JSON.stringify(this.sonvalue))
        // let serviceInfo=encodeURIComponent(JSON.stringify(this.serviceInfo))
        // uni.redirectTo({
        // 	url:`./index?item=${items}&serviceInfo=${serviceInfo}`
        // })

        // undoneConsult(this.sonvalue.patientId, store.state.app.serviceUid)
        //   .then((res) => {
        //     this.type = this.typeStatus[res.data.type]
        //     console.log(this.type)
        //     if (res.data.isExist == 0) {
        //       uni.showToast({
        //         title: '存在未完成的' + this.type,
        //         icon: 'none',
        //         duration: 3000,
        //       })
        //     } else {
        //       uni.redirectTo({
        //         url: `./index?item=${items}&serviceInfo=${serviceInfo}`,
        //       })
        //     }
        //   })
        //   .catch((err) => {
        //     console.log(err)
        //   })
      } else {
        uni.showToast({
          title: '请选择就诊人',
          icon: 'none',
          duration: 3000,
        })
      }
      if (this.sonvalue.isVerified == 1) {
        uni.showToast({
          title: '该就诊人未实名，请去实名',
          icon: 'none',
          duration: 3000,
        })
        return
      }
    },
    choosePeople(data) {
      this.choosePeopleInfo = data
    },
    editor() {
      uni.navigateTo({
        url: `/pagesSub-My/my/editPatients?patientId=${this.sonvalue.patientId}`,
      })
    },
  },
}
</script>

<style scoped>
.content {
  padding: 10rpx;
  display: flex;
  flex-wrap: wrap;
}
.content view {
  /* width: 150rpx; */
  margin-left: 10rpx;
  padding: 10rpx;
  background-color: #ffffff;
  border-radius: 10rpx;
  /* margin-right: 20rpx; */
  margin-bottom: 20rpx;
}
.introduce {
  font-size: 29rpx;
}

.introduce text {
  margin-right: 20rpx;
}
.btn_appointment {
  margin-top: 40rpx;
  background: -webkit-linear-gradient(#77e2a4, #4ccdbc);
  color: #ffffff;
}
</style>
